package com.th.common.core.page;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.util.Map;

/**
 * 分页查询数据传输对象</b>
 * 现在只用于后台分页查询接口使用
 *
 * @author tuhang
 */
public class PageQueryDTO {

    /**
     * 查询参数表中的参数，表示<b>要查询的关键字</b>
     */
    public static final String PARAMS_KEYWORD = "keyword";
    /**
     * 排序参数，表示<b>要排序的字段</b>
     */
    public static final String PARAMS_SORTS = "sorts";
    @NotNull(message = "分页参数不能为空")
    @Min(value = 1, message = "页号最小为1")
    private Integer current;
    @NotNull(message = "每页数量不能为空")
    @Max(value = 500, message = "每页最大为500")
    private Integer size;
    private Map<String, Object> params;


    public Integer getCurrent() {
        return current;
    }

    public void setCurrent(Integer current) {
        this.current = current;
    }

    public Integer getSize() {
        return size;
    }

    public void setSize(Integer size) {
        this.size = size;
    }

    public void setParams(Map<String, Object> params) {
        this.params = params;
    }

    public Map<String, Object> getParams() {
        return  this.params;
    }

    public Object getParam(String key) {
        if (params == null) {
            return null;
        }

        return params.getOrDefault(key, null);
    }
}
